#ifndef BSP_CAN_H
#define BSP_CAN_H
#include "mytype.h"


extern void can_filter_init(void);


#define CHASSIS_CAN hcan1
#define GIMBAL_CAN hcan2

/* CAN send and receive ID */
typedef enum
{
    CAN_CHASSIS_ALL_ID_1_4 = 0x200,
    CAN_CHASSIS_3508_M1_ID = 0x201,
    CAN_CHASSIS_3508_M2_ID = 0x202,
    CAN_CHASSIS_3508_M3_ID = 0x203,
    CAN_CHASSIS_3508_M4_ID = 0x204,
		CAN_CHASSIS_ALL_ID_5_8 = 0x1FF,
		CAN_CHASSIS_3508_M5_ID = 0x205,  // 全向轮
		CAN_CHASSIS_3508_M6_ID = 0x206,  // 全向轮

    CAN_GIMBAL_ALL_ID_1_4 = 0x200,
    CAN_GIMBAL_3508_M1_ID = 0x201,
    CAN_GIMBAL_3508_M2_ID = 0x202,
    CAN_GIMBAL_3508_M3_ID = 0x203,
    CAN_GIMBAL_3508_M4_ID = 0x204,
    CAN_GIMBAL_ALL_ID_5_8 = 0x1FF,
		CAN_GIMBAL_2006_ID = 0x205
} can_msg_id_e;

//rm motor data
typedef struct
{
    uint16_t ecd;
    int16_t speed_rpm;
    int16_t given_current;
    uint8_t temperate;
    int16_t last_ecd;
} motor_measure_t;

extern motor_measure_t  motor_chassis[];
extern motor_measure_t 	motor_gimbal[];
/**
  * @brief          send control current of motor (0x205, 0x206, 0x207, 0x208)
  * @param[in]      yaw: (0x205) 6020 motor control current, range [-30000,30000] 
  * @param[in]      pitch: (0x206) 6020 motor control current, range [-30000,30000]
  * @param[in]      shoot: (0x207) 2006 motor control current, range [-10000,10000]
  * @param[in]      rev: (0x208) reserve motor control current
  * @retval         none
  */
/**
  * @brief          ·¢ËÍµç»ú¿ØÖÆµçÁ÷(0x205,0x206,0x207,0x208)
  * @param[in]      yaw: (0x205) 6020µç»ú¿ØÖÆµçÁ÷, ·¶Î§ [-30000,30000]
  * @param[in]      pitch: (0x206) 6020µç»ú¿ØÖÆµçÁ÷, ·¶Î§ [-30000,30000]
  * @param[in]      shoot: (0x207) 2006µç»ú¿ØÖÆµçÁ÷, ·¶Î§ [-10000,10000]
  * @param[in]      rev: (0x208) ±£Áô£¬µç»ú¿ØÖÆµçÁ÷
  * @retval         none
  */
extern void CAN_cmd_gimbal(int16_t motor1, int16_t motor2, int16_t motor3, int16_t motor4, int16_t motor5);

/**
  * @brief          send CAN packet of ID 0x700, it will set chassis motor 3508 to quick ID setting
  * @param[in]      none
  * @retval         none
  */
/**
  * @brief          ·¢ËÍIDÎª0x700µÄCAN°ü,Ëü»áÉèÖÃ3508µç»ú½øÈë¿ìËÙÉèÖÃID
  * @param[in]      none
  * @retval         none
  */
extern void CAN_cmd_chassis_reset_ID(void);

/**
  * @brief          send control current of motor (0x201, 0x202, 0x203, 0x204)
  * @param[in]      motor1: (0x201) 3508 motor control current, range [-16384,16384] 
  * @param[in]      motor2: (0x202) 3508 motor control current, range [-16384,16384] 
  * @param[in]      motor3: (0x203) 3508 motor control current, range [-16384,16384] 
  * @param[in]      motor4: (0x204) 3508 motor control current, range [-16384,16384] 
  * @retval         none
  */
/**
  * @brief          ·¢ËÍµç»ú¿ØÖÆµçÁ÷(0x201,0x202,0x203,0x204)
  * @param[in]      motor1: (0x201) 3508µç»ú¿ØÖÆµçÁ÷, ·¶Î§ [-16384,16384]
  * @param[in]      motor2: (0x202) 3508µç»ú¿ØÖÆµçÁ÷, ·¶Î§ [-16384,16384]
  * @param[in]      motor3: (0x203) 3508µç»ú¿ØÖÆµçÁ÷, ·¶Î§ [-16384,16384]
  * @param[in]      motor4: (0x204) 3508µç»ú¿ØÖÆµçÁ÷, ·¶Î§ [-16384,16384]
  * @retval         none
  */
extern void CAN_cmd_chassis(int16_t motor1, int16_t motor2, int16_t motor3, int16_t motor4, int16_t motor5, int16_t motor6);

/**
  * @brief          return the yaw 6020 motor data point
  * @param[in]      none
  * @retval         motor data point
  */
/**
  * @brief          ·µ»Øyaw 6020µç»úÊý¾ÝÖ¸Õë
  * @param[in]      none
  * @retval         µç»úÊý¾ÝÖ¸Õë
  */
extern const motor_measure_t *get_yaw_gimbal_motor_measure_point(void);

/**
  * @brief          return the pitch 6020 motor data point
  * @param[in]      none
  * @retval         motor data point
  */
/**
  * @brief          ·µ»Øpitch 6020µç»úÊý¾ÝÖ¸Õë
  * @param[in]      none
  * @retval         µç»úÊý¾ÝÖ¸Õë
  */
extern const motor_measure_t *get_pitch_gimbal_motor_measure_point(void);

/**
  * @brief          return the trigger 2006 motor data point
  * @param[in]      none
  * @retval         motor data point
  */
/**
  * @brief          ·µ»Ø²¦µ¯µç»ú 2006µç»úÊý¾ÝÖ¸Õë
  * @param[in]      none
  * @retval         µç»úÊý¾ÝÖ¸Õë
  */
extern const motor_measure_t *get_trigger_motor_measure_point(void);

/**
  * @brief          return the chassis 3508 motor data point
  * @param[in]      i: motor number,range [0,3]
  * @retval         motor data point
  */
/**
  * @brief          ·µ»Øµ×ÅÌµç»ú 3508µç»úÊý¾ÝÖ¸Õë
  * @param[in]      i: µç»ú±àºÅ,·¶Î§[0,3]
  * @retval         µç»úÊý¾ÝÖ¸Õë
  */
extern const motor_measure_t *get_chassis_motor_measure_point(uint8_t i);

#endif
